<template>
    <v-container>
        <Tiptap v-model="content"></Tiptap>
        <v-divider class="mb-4"></v-divider>
        <v-row dense no-gutters>
            <v-col>
                <v-btn depressed color="primary" class="mr-2" @click="save" :loading="saving">保存</v-btn>
            </v-col>
        </v-row>

    </v-container>
</template>

<script>
    import axios from "axios";
    import Tiptap from "../../../widgets/Tiptap.vue";


    export default {
        data: () => ({
            content: '',
            saving: false
        }),

        components: {
            Tiptap,
        },


        created() {
            this.load();
        },

        methods: {
            load() {
                axios.get(`/app/setting/rules`).then((response) => {
                    if(response.data.code == 0) {
                        this.content = response.data.data ?  response.data.data : '';
                    }
                })
                .catch(function () {})
                .then(function () {
                });
            },

            save() {
                this.saving = true;
                const that = this;
                axios.post(`/app/setting/rules`, {value: this.content}).then((response) => {
                    this.$toast.open({
                        message: response.data.msg,
                        type: response.data.code == 0 ? 'success' : 'error',
                        position: 'top-right',
                    });
                })
                .catch(function () {})
                .then(function () {
                    that.saving = false;
                });
            }
        }
    }
</script>